// pages/ordersuccess/ordersuccess.js
var app = getApp();
var utils = require('../../utils/util.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        ishise: false
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var that = this;
        that.setData({
            orderid: options.orderid,
            totalprice: options.totalprice,
            orderType: options.orderType,
            goodsid: options.goodsid
        })
        that.groupgoodsDetail();
        that.memberInfo();
        var url = 'https://xinong.qidian2018.com/index.php?share_id=1&type=1&id=' + options.goodsid;
        that.setData({
            qrcodeValue: url,
        })
    },
    //分享弹窗
    onshareTap: function(e) {
        this.setData({
            ishise: true
        })
    },
    buttonOrderCalse: function(e) {
        this.setData({
            ishise: false
        })
    },
    saveCanvas: function () {
        var that = this;
        var url = 'https://xinong.qidian2018.com/index.php?share_id=1&type=1&id=' + that.data.goodsid
        that.setData({
            qrcodeValue: url,
        }, function () {
            var canvas = that.selectComponent('#goods-share');
            canvas.saveImg();
        })
    },
    //跳转首页
    onindexTap: function(e) {
        wx.switchTab({
            url: '../index/index',
        })
    },
    groupgoodsDetail: function (id) {
        var that = this;
        utils.showLoading();
        utils.http("/api/v1/groupgoods/goods_detail", {
            id: that.data.goodsid
        }, function (res) {
            utils.hideLoading();
            that.setData({
                data: res.datas,
            })
            console.log(that.data)
        })
    },
    
    //用户详情
    memberInfo: function () {
        var that = this;
        utils.http("/api/v1/member/index", {}, function (res) {
            that.setData({
                memberInfo: res.datas
            })
        });
    },   
    
     //跳转订单详情
    onOrderDetailsTap: function(e) {
        // wx.navigateTo({
        //     url: '../orderdetails/orderdetails',
        // })
        // wx.redirectTo({
        //   url: '../personal/myorderdetails/myorderdetails?id=' + this.data.orderid,
        // })
        wx.redirectTo({
            url: '/pages/personal/myorder/myorder?stateid=10000&stateindex=0'
        })

    },
    onShareAppMessage: function () {
        return utils.share();
    },
})